import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Vector;


public class roomInfo {
	
	// basic info of room
	private int roomNum;
	// info of host
	private Vector<host> hosts;
	private host current;
	
	
	public roomInfo(int initRoomNum){
		roomNum = initRoomNum;
		hosts = new Vector<host>();
		initialize();
	}

	// initialize room
	public void initialize() {
		current = new host("", -1, -1, -1, "", "", "", "", -1);
	}
	
	public void setCurrentHost(host initHost){ 
		current = initHost;
		if (hosts.contains(current))
			hosts.remove(current);
	}
	// if the time is occupied, then return false
	public boolean addReservation(host initHost){ 
		if (hosts.contains(initHost))
			return false;
		else hosts.add(initHost);
		return true;
	}
	
	public int getRoomNum()								{ return roomNum;}
	public host getCurrent()							{ return current;}
	public Vector<host> getHosts()						{ return hosts;}
	
	// find and delete reservation when reaching the reserved time
	public boolean deleteReservation(String hostName, String initTime){
		for (int i=0; i<hosts.size(); i++)
			if (hosts.get(i).getName().equals(hostName)
					&& hosts.get(i).getStartTime().equals(initTime)){
				hosts.remove(i);
				return true;
			}
		return false;
	}
	
	public String toString(){
		String s = "";
		s+="Host Name: \t"+current.getName()+"\n";
		s+="People Amount: \t"+current.getAmount()+"\n";
		DateFormat format = new SimpleDateFormat("yyyy/MM/dd hh:mm");
		if (!current.getName().equals("")){
			s+="Start Time: \t"+format.format(current.getStartTime().getTime())+"\n";
			s+="Total Minutes: \t"+current.getTotalMin()+"\n";
			s+="End Time: \t"+format.format(current.getEndTime().getTime())+"\n";
		}
		else {
			s+="Start Time: \n";
			s+="Total Minutes: \n";
			s+="End Time: \n";
		}
		return s;
	}
	
	// check whether the time is in the occupied period
	public boolean in( Calendar c){
		if (getCurrent().in(c))
			return true;
		Vector<host> roomHosts = getHosts();
		for (int i=0; i<roomHosts.size(); i++)
			if (roomHosts.get(i).in(c))
				return true;
		return false;
	}
}
